import fetch from '../config/fetch'
import { snxd, img, cmslib, comment ,tps, shop ,pro, pua  } from '../config/env'
import * as env from '../config/env'

var getBizTime = (params) => fetch({
  url: env.snxd + '/storeInfo/getCurrentBusinessStateJsonp.do',
  params: params
});

// 获取页面配置
var getHomePage = (params) => fetch({
  url: env.snxd + '/home/getPoiInfoHomePageNew.do',
  params: params
});

// 获取导航信息
var getHomeNav = (params) => fetch({
  url: env.cmslib + '/api/jsonp/cb/' + params.pageparam + '-gethomenav.jsonp',
  params: {},
  jsonp: 'callback',
  jsonpCallback: 'gethomenav'
});

// 获取内容
var getHomeContent = (params) => fetch({
  url: env.cmslib + '/api/aysn/page/' + params.pageparam + '.jsonp',
  params: {},
  jsonp: 'callback',
  jsonpCallback: 'cmsPageCallback'
});

/**
 * 购物车api
 */
// 获取小店购物车
var getSufreshCarts = (params) => fetch({
  url: env.tps + '/app/cart1/gateway/showCartOneInfo.do',
  params: params,
  jsonp: 'callBack'
});

// 获取小店中心仓购物车
var getCenterCarts = (params) => fetch({
  url: env.shop + '/xd-cart-web/cloud/cart1/showCartInfo.do',
  params: params
});

// 同步购物车
var addCartInfo = (params) => fetch({
	url: env.tps + '/app/cart1/gateway/synchronizeCmmdty.do',
	params: {
		'data': params
	},
	type: 'post'
});

// 同步中心仓购物车
var addCenterInfo = (params) => fetch({
  url: shop + '/xd-cart-web/cloud/cart1/addCart.do',
  params: {
    'data': params
  },
  type: 'post'
});




// 修改小店购物车
var updateCartInfo = (params) => fetch({
	url: env.tps + '/app/cart1/gateway/updateTempCartInfo.do',
	params: {
		'data': params
	},
	type: 'post'
});

// ************四级页
//商品信息
var getDatailContent = (params) => fetch({
	url: pro+'/api/cmmdty/getCmmdtyInfoV3Jsonp/'+params.cityCode+'_'+params.storeLocation+'_'+params.cmmdtyCode+'_'+params.supplierCode+'_wap_3.2.2_heh.htm',///api/cmmdty/getCmmdtyInfoJsonp/'+params.cityCode+'_'+params.storeLocation+'_'+params.cmmdtyCode+'_getProInfo.htm
	params: {},
	jsonp: 'callback',
	jsonpCallback: 'heh'
});
//中心仓商品价格
var getCenterPrice = (params) => fetch({
	url: pro+'/price/getCmmdtyPriceListV2Jsonp/'+params.cityCode+'_'+params.storeLocation+'_'+params.cmmdtyCode+'-'+params.supplierCode+'_'+params.app+'_'+params.appVersion+'_getprice.do', 
	params: params.rand,
	jsonp: 'callback',
	jsonpCallback: 'getprice'
});
//小店的商品价格
var getstorePrice = (params) => fetch({
  url: pro+'/store/cmmdty/getCmmdtyPriceListJsonpV2/'+params.cityCode+'_'+params.storeLocation+'_'+params.cmmdtyCode+'_getprice.do', 
  params: {},
  jsonp: 'callback',
  jsonpCallback: 'getprice'
});
//商品的送达消息
var nssnitem = (params) => fetch({
  url: pua+'/nssnitemsale_'+params.cmmdtyCode+'_'+params.supplierCode+'_'+params.provCode+'_'+params.lesCityCode+'_'+params.distCode+'_0_5__12.html', 
  params: {},
  jsonp: 'callback',
  jsonpCallback: 'wapData'
});
 
 var nssndetail = (params) => fetch({
  url: pua+'/nssndetail_'+params.cmmdtyCode+'_'+params.supplierCode+'_'+params.lesCityCode+'_'+params.distCode+'_5_'+params.categoryCode+'_'+params.catalogId+'_'+params.price+'__'+params.provCode+'_'+params.salesOrgP+'_'+params.ownerPlaceP+'_'+params.vendor+'_'+params.netPrice+'_0_'+params.cmmdtyCode+'_12_'+params.priceType+'_'+params.brandCode+'__'+params.brandId+'_'+params.categoryId+'_0_0.html',
  params: {},
  jsonp: 'callback',
  jsonpCallback: 'detailCommonLogic'
});

//
var getDatailTime = (params) => fetch({
	url: snxd+'/storeInfo/getCurrentBusinessStateJsonp.do',
	params: params,
	jsonp: 'callBack',
	jsonpCallback: 'getBizTime'
});

 
//中心仓达时间
var getDataillivery1 = (params) => fetch({
	 url : pro+'/center/cmmdty/serviceInfoJsonp/025_' + params.storeCode + '_' + params.cmmdtyCode + '_0000000000_' + params.ownerPlace + '_' + params.deptNo + '_' + params.purchaseFlag + '_' + params.accountPlace + '_' + params.price + '_getDelivery.htm',
	params: params.rand,
	jsonp: 'callBack',
	jsonpCallback: 'getDelivery'
});
//小店达时间
var getDataillivery2 = (params) => fetch({
	url: pro+'/store/cmmdty/serviceInfoJsonp/'+params.storeCode+'_'+params.cmmdtyCode+'_'+params.cmmdtyType+'_'+params.price+'_getDelivery.do',
	params: params.rand,
	jsonp: 'callBack',
	jsonpCallback: 'getDelivery'
});

//评价
var getCommentProfile = (params) => fetch({
  // /mobile/getFirstTwoReviews/general-'+params.cmmdtyCode+'--total-1-10-1-1-1-1-getCommentProfile.htm
	url: comment+'/mobile/getFirstTwoReviews/general-'+params.cmmdtyCode+'-'+params.supplierCode+'--------getCommentProfile.htm',
	params: params.rand,
	jsonp: 'callback',
	jsonpCallback: 'getCommentProfile'
});
 
//评价概况
var getCommentCount = (params) => fetch({
	url: comment+'/mobile/getReviewCnt/general-'+params.cmmdtyCode+'-'+params.supplierCode+'-----getCommentCount.htm',
	params: params.rand,
	jsonp: 'callback',
	jsonpCallback: 'getCommentCount'
});
//评价主内容
var getCommentList = (params) => fetch({
	url: comment+'/mobile/getReviewList/general-'+params.cmmdtyCode+'-'+params.supplierCode+'-'+params.tabname+'-'+params.num+'-default-10-----getCommentList'+params.num+'.htm',
	params: params.rand,
	jsonp: 'callback',
	jsonpCallback: 'getCommentList'+params.num
});

//评价回复概况
var UsefulReply = (params) => fetch({
  url: comment+'/mobile/getUsefulReplyCnt/'+params.commodityReviewId+'-UsefulReply.htm',
  params: params.rand,
  jsonp: 'callback',
  jsonpCallback: 'UsefulReply'
 });//

// //获取购物车的数量
var getCart = (params) => fetch({
	url: tps+'/app/cart1/gateway/showCartOneInfo.do',
	params: params,
	jsonp: 'callBack',
	jsonpCallback: 'getCart'
});
var num = 2
var getBusy = (params) => fetch({
	url: pro+'/business/getBusinessInfo.htm',
	params: params,
	jsonp: 'callback',
	jsonpCallback: 'jsonp'+(num++)
});
//列表页的顶部tab名字
var levelCatalog = (params) => fetch({
	url: pro+'/catalog/getSameLevelCatalog/'+params.storeCode+'_'+params.catalogCode+'_levelCatalogCallback.jsonp',
	params: params.rand,
	jsonp: 'callback',
	jsonpCallback: 'levelCatalogCallback'
});
//获取列表页的商品
var listshop = (params) => fetch({
	url: pro+'/cmmdty/searchCmmdty.do',
	params: params.data,
	jsonp: 'callback',
	jsonpCallback: 'jsonp'+params.jsonnum
});

// getSufreshCarts
// getSufreshCarts


// // 修改中心仓购物车
// var updateCenterCartInfo = (params) => fetch({
//   url: env.shop + '/xd-cart-web/cloud/cart1/updateCartInfo.do',
//   params: params,
//   type: 'post'
// =======
// 修改中心仓购物车
var updateCenterCartInfo = (params) => fetch({
	url: env.shop + '/xd-cart-web/cloud/cart1/updateCartInfo.do',
	params: {
		'data': params
	},
	type: 'post'
});

// 去结算
var settlementInfo = (params) => fetch({
	url: env.tps + '/app/cart1/private/settlement.do',
	// params: {
	// 	'data': params
	// },
	params: params,
	type: 'post'
});

// 中心仓去结算
var settlementCenterInfo = (params) => fetch({
	url: env.shop + '/xd-cart-web/cloud/cart1/settlement.do',
	params: params,
	type: 'post'
});

var getSuningCarts = (params) => fetch({
  url: env.shop + '/xd-cart-web/cloud/cart1/showCartInfo.do',
  params: params
});

// 获取商品信息
var getCommodityData = (cityCode, storeCode, ids) => {
  let cb = 'cb'+parseInt(Math.random()*1000000);
  return fetch({
    url: `${env.pro}/homePage/getCmmdtysV2Jsonp/${cityCode}_${storeCode}_${ids}_wap_3.2.2_${cb}.htm`,//3.0.0
    params: {},
    jsonp: 'callback',
    jsonpCallback: cb
  })
}

var getprice = (params) => fetch({
  url: pro+'/price/getCmmdtyPriceListV2Jsonp/'+params.cityCode+'_'+params.storeCode+'_'+params.shopcmmdtyCode.join(',')+'_'+params.app+'_'+params.appVersion+'_getPro'+params.num+'.do',
  params: {
    _ : params.num
  },
  jsonp: 'callback',
  jsonpCallback: 'getPro'+params.num
});

//商品列表页
var catalog = (params) => fetch({
  // url: pro+'/catalog/getCatalog/'+params.storeCode+'_catalog.jsonp',
  url: pro+'/catalog/getCatalogNew/'+params.storeCode+'_'+params.wap+'_wap.htm',//android
  params: {
    _ : params._
  },
  jsonp: 'callback',
  jsonpCallback: 'catalog'
});

//搜索文案，搜索框里的文字
var SearchInfo = (params) => fetch({
      // url: pro+'/catalog/getCatalog/'+params.storeCode+'_catalog.jsonp',
      url: pro+'/api/cmmdty/getSearchInfo/2_'+params.num+'_SearchInfo.htm', 
      params: {
        _ : params._
      },
      jsonp: 'callback',
      jsonpCallback: 'SearchInfo'
});

//发票确定
var InvoiceInfo = (params) => fetch({
      // url: pro+'/catalog/getCatalog/'+params.storeCode+'_catalog.jsonp',
      url: shop+'/xd-cart-web/cloud/cart2/recInvoiceInfo.do',
      params: params, 
      type: 'post'
})
//查询发票的信息
var queryInvoice = (params) => fetch({
      // url: pro+'/catalog/getCatalog/'+params.storeCode+'_catalog.jsonp',
      url: shop+'/xd-cart-web/cloud/cart2/queryInvoiceInfo.do', 
      params: params,
      jsonp: 'callback',
      jsonpCallback: 'queryInvoice'
});

//通过citycode与storeLocation获取省市区
var getarea = (params) => fetch({
      // url: pro+'/catalog/getCatalog/'+params.storeCode+'_catalog.jsonp',
      url: snxd+'/home/getPoiInfoHomePageNew.do', 
      params: params,
      jsonp: 'callback'
});

// 首页搜索框
var homePageSearchMsg = (params) => fetch({
	url: `${pro}/api/cmmdty/getSearchInfo/2_1_SearchInfo.htm?_=${Math.random()*10000000}`,
	params: {},
	jsonp: 'callback',
  jsonpCallback: 'SearchInfo'
});

// 获取服务器当前时间
var getServiceTime = () => fetch({
  url: '//f.m.suning.com/api/ct.do',
  params: {}
});

//热搜
var hotsearch = (params) => fetch({
  url: pro + '/api/cmmdty/getSearchInfo/1__jsonp1.htm',
  params: params,
  jsonp: 'callback',
  jsonpCallback: 'jsonp1'
});

//联系苏鲜生
var gettelcall = (params) => fetch({
  url: snxd + '/switch/switchList.do',
  params: params,
  jsonp: 'callback',
  jsonpCallback: 'gettelcall'
});
//个人中心小店的优惠卷与中心仓优惠卷公用的
var storecoupon = (params) => fetch({
  url: tps+params.url,
  params: {
    couponRemark: params.couponRemark
  },
  jsonp: 'callBack',
  jsonpCallback: 'storecoupon'
});
//个人中心中心仓单张优惠卷的信息
var centerCouponInfo = (params) => fetch({
  url: tps+'/app/coupon/queryAccountCouponInfo.do',
  params: params,
  jsonp: 'callBack',
  jsonpCallback: 'centerCouponInfo'
});

//车2小店的优惠卷
var Cart2storecoupon = (params) => fetch({
  url: tps+params.url,
  params: params.data,
  jsonp: 'callBack',
  jsonpCallback: 'Cart2storecoupon'
});
//车2中心仓的优惠卷
var Cart2centercoupon = (params) => fetch({
  url: shop+'/xd-cart-web/cloud/cardcoupon/private/queryCouponListInfo.do',
  params: params,
  jsonp: 'callback',
  jsonpCallback: 'Cart2scentercoupon'
});

//四级页小店领优惠券的信息 
var getvolume = (params) => fetch({
  url: env.icp+'/icps-web/queryPromotionTags/'+params.cmmdtyCode+'_'+params.bizCode+'_'+params.area+'_'+params.cityCode+'_'+params.snPrice+'_'+params.type+'_'+params.num+'_'+params.chan+'_'+params.bonusId+'__getvolume.vhtm',
  params: {},
  jsonp: 'callback',
   jsonpCallback: 'getvolume'
});

//爆炸贴
//https://pcsslabel.suning.cn/pcss-web/label/poplabels.do?params=%5B%7BcmmdtyCode:000000000104006735,supplierCode:0000000000,channel:SNXD,labelScene:03%7D,%7BcmmdtyCode:000000000104006735,supplierCode:0000000000,channel:SNXD,labelScene:04%7D,%7BcmmdtyCode:000000000104006735,supplierCode:0000000000,channel:SNXD,labelScene:06%7D%5D&
var getpcss =  (params) => fetch({
  url: env.pcss+'/label/poplabels.do',
  params: params,
  jsonp: 'callback',
  jsonpCallback: 'getpcss'
});
 
export {
  getBizTime,
  getHomePage,
  getHomeNav,
  getHomeContent,
  getSufreshCarts,
  getSuningCarts,
  getCommodityData,
  getCenterCarts,
  addCartInfo,
  updateCartInfo,
  updateCenterCartInfo,
  hotsearch,
  UsefulReply,
  gettelcall,
  storecoupon,
  centerCouponInfo,
  Cart2storecoupon,
  Cart2centercoupon,

  getDatailContent,
  getCenterPrice,
  getstorePrice,
  getDatailTime,
  getDataillivery1,
  getDataillivery2,
  getCommentProfile,
  getCommentCount,
  getCommentList,
  getCart,
  getBusy,
  levelCatalog,
  listshop,
  getprice,
  catalog,
  addCenterInfo,
  SearchInfo,
  InvoiceInfo,
  queryInvoice,
  getarea,
  nssnitem,
  nssndetail,

  settlementInfo,
  settlementCenterInfo,
	homePageSearchMsg,
  getServiceTime,
  getvolume,
  getpcss
}
